package controllers;

import game.Projectile;

import java.util.ArrayList;

/**
 * Projectile controller. Manages all fired projectiles.
 * @author Twisty
 *
 */
public class ProjectileController {
	// All fired projectiles.
	private static ArrayList<Projectile> projectiles = new ArrayList<Projectile>();
	
	/**
	 * Private constructor, cannot be called.
	 */
	private ProjectileController(){
	}
	

	/**
	 * Get all projectiles.
	 * @return All projectiles
	 * @throws Exception
	 */
	public static ArrayList<Projectile> getProjectiles() throws Exception{
		return projectiles;
	}
	
	/**
	 * Add a projectile to the list.
	 * @param p	The projectile to add.
	 */
	public static void addProjectile(Projectile p){
		projectiles.add(p);
	}
	
	/**
	 * Check and remove all inactive projectiles.
	 */
	public static void checkRemove(){
		try{
			for(Projectile p: projectiles){
				if(!p.isActive()){
					projectiles.remove(p);
				}
			}
		}catch(Exception e){
		}
	}
	
	/**
	 * Remove all projectiles from the list.
	 */
	public static void removeAllProjectiles(){
		projectiles.clear();
		projectiles = new ArrayList<Projectile>();
	}
	
}
